/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.cvut.fel.taskpro.business.manager;

import cz.cvut.fel.taskpro.business.imanager.ISubjectBusiness;
import cz.cvut.fel.taskpro.business.isupport.IBusinessRuleValidator;
import cz.cvut.fel.taskpro.business.support.BusinessRuleException;
import cz.cvut.fel.taskpro.data.entity.Kantor;
import cz.cvut.fel.taskpro.data.entity.Student;
import cz.cvut.fel.taskpro.data.entity.Subject;
import cz.cvut.fel.taskpro.data.imanager.ISubjectData;
import cz.cvut.fel.taskpro.data.imanager.IUserData;
import java.io.Serializable;
import java.util.List;
import javax.annotation.security.DeclareRoles;
import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.inject.Inject;


/**
 * This class implement #{@link ISubjectBusiness} interface
 * @author Tom
 * @version 1.0. beta
 */
@DeclareRoles({"admin", "kantor", "student"})
@Stateless
public class SubjectBusiness implements ISubjectBusiness, Serializable {

    @Inject
    private ISubjectData subjectData;
    @Inject
    private IUserData userData;
    @EJB
    private IBusinessRuleValidator validator;

    public SubjectBusiness() {
    }

    @Override
    public void addSubject(Subject newSubject) throws BusinessRuleException {
        validator.validateAding(newSubject);
        subjectData.addSubject(newSubject);
    }

    @PermitAll
    @Override
    public List<Subject> showSubjects(String kod) {
        System.out.println(kod);
        return (List<Subject>) subjectData.getSubjectByCode(kod);

    }
    @RolesAllowed("admin")
    @Override
    public List<Subject> showSubjects() {
        return subjectData.getAllSubject(); //dsada
    }

    @RolesAllowed("admin")
    @Override
    public void removeSubject(String code) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @PermitAll
    @Override
    public List<Subject> getSubjectsByTeacher(Kantor kantor) throws BusinessRuleException {
        validator.validate(kantor);
        return subjectData.getSubjecByKantor(kantor);
    }

    @PermitAll
    @Override
    public List<Subject> getStudentsSubjects(Student loggedStudent) throws BusinessRuleException {
        validator.validate(loggedStudent);
        return subjectData.getStudentsSubject(loggedStudent);

    }
}
